package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.pojo.QuestionnaireReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service(version = "1.0.0")
public class QuestionnaireReportApiImpl implements QuestionnaireReportApi {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public String saveReport(QuestionnaireReport questionnaireReport) {
        this.mongoTemplate.save(questionnaireReport);
        return questionnaireReport.getId().toHexString();
    }

    @Override
    public List<QuestionnaireReport> querySimilarYou(String conclusion) {
        Query query = Query.query(Criteria.where("conclusion").is(conclusion));
        List<QuestionnaireReport> questionnaireReports = this.mongoTemplate.find(query, QuestionnaireReport.class);
        return questionnaireReports;
    }

    @Override
    public QuestionnaireReport queryByReportId(String id) {
        Query query = Query.query(Criteria.where("id").is(id));
        QuestionnaireReport questionnaireReport = this.mongoTemplate.findOne(query, QuestionnaireReport.class);
        return questionnaireReport;
    }


}
